package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.Build;
import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Player;
import com.xcity.game.buildv2.BuildV2;
import com.xcity.pomelo.response.EmployeeInfoResponse.EmployeeSimpleInfo;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class DefendOtherBuildResponse extends Response {
	
	private long pid;
	private int bid;
	private List<EmployeeSimpleInfo> employees = Collections.emptyList();
	private byte type; // 操作类型:1-派员工占领,0-放弃占领
	
	public DefendOtherBuildResponse(int serial) {
		super(serial);
	}
	
	@Deprecated
	public DefendOtherBuildResponse(int serial, Build build, byte type) {
		super(serial);
		this.pid = build.getManager().getOwner().getId();
		this.bid = build.getId();
		Player owner = build.owner();
		long[] employeeIds = build.employees();
		if (employeeIds != null) {
			employees = new ArrayList<EmployeeSimpleInfo>(employeeIds.length);
			for (long id : employeeIds) {
				Employee e;
				if (id != 0 && (e = owner.getEmployees().get(id)) != null) {
					employees.add(new com.xcity.pomelo.response.BuildStatusResponse.EmployeeSimpleInfo(e));
				} else {
					employees.add(EmployeeSimpleInfo.EMPTY);
				}
			}
		}
		this.type = type;
	}
	
	public DefendOtherBuildResponse(int serial, BuildV2 build, byte type) {
		super(serial);
		this.pid = build.getVm().getOwner().getId();
		this.bid = build.getId();
		Player owner = build.currentOwner();
		long[] employeeIds = build.currentEmployees();
		if (employeeIds != null) {
			employees = new ArrayList<EmployeeSimpleInfo>(employeeIds.length);
			for (long id : employeeIds) {
				Employee e;
				if (id != 0 && (e = owner.getEmployees().get(id)) != null) {
					employees.add(new com.xcity.pomelo.response.BuildStatusResponse.EmployeeSimpleInfo(e));
				} else {
					employees.add(EmployeeSimpleInfo.EMPTY);
				}
			}
		}
		this.type = type;
	}
	
	public long getPid() {
		return pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}

	public int getBid() {
		return bid;
	}

	public void setBid(int bid) {
		this.bid = bid;
	}

	public List<EmployeeSimpleInfo> getEmployees() {
		return employees;
	}

	public void setEmployees(List<EmployeeSimpleInfo> employees) {
		this.employees = employees;
	}

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}
	
}
